﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MyFinanceManager.Controls
{
    public partial class cUpAndDowner : UserControl
    {
        public cUpAndDowner()
        {
            InitializeComponent();
        }

        int value = 0;
        int maxValue = 9;

        public int Value
        {
            get { return this.value; }
            set
            {
                this.value = value;
                if (value > maxValue)
                    this.value = 0;
                else if (value < 0)
                    this.value = maxValue;
                this.label1.Text = this.value.ToString("0");
            }
        }

        public int Max
        {
            get { return maxValue; }
            set { maxValue = value; }
        }

        private void btMehr_Click(object sender, EventArgs e)
        {
            value++;
            if (value > maxValue)
                value = 0;
            this.label1.Text = value.ToString("0");
            
            FireValueChanged();
        }

        private void btWeniger_Click(object sender, EventArgs e)
        {
            value--;
            if (value < 0)
                value = maxValue;
            this.label1.Text = value.ToString("0");

            FireValueChanged();
        }

        private void FireValueChanged()
        {
            EventHandler temp = ValueChanged;
            if (temp != null)
            {
                temp(this, null);
            }
        }

        public event EventHandler ValueChanged;
    }
}
